package view.login;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import view.CadastroMae;
import view.windowBehavior.McWinLookAndFeelBehavior;
import view.windowBehavior.WindowBehavior;

public class Login extends CadastroMae  {

	private JLabel lbLogin;
	private JLabel lbSenha;

	private JTextField txLogin;
	private JPasswordField password;

	private JButton btEntrar;
	private JButton btCancelar;

	private JPanel painelEsquerdo;
	private JPanel painelCentro;
	private JPanel painelSul;

	private WindowBehavior windowBehavior;

	public Login(ActionListener controler) {
		super("Login e Senha", 300, 190, controler);
		setTitle("Seja Bem-Vindo!");
	}

	@Override
	public void exibir() {
		setVisible(true);
	}

	@Override
	public void fechar() {
		dispose();
	}

	@Override
	protected void init() {
		super.init();
		windowBehavior = new McWinLookAndFeelBehavior();

		getPainelForm().setBorder(new TitledBorder(getTitle()));

		lbLogin = new JLabel("Login:");
		lbSenha = new JLabel("Senha:");

		txLogin = new JTextField(20);
		password = new JPasswordField(20);
		password.setActionCommand("entrar");
		password.addActionListener(controller);

		this.btEntrar = new JButton("Entrar");
		this.btEntrar.addActionListener(controller);
		this.btEntrar.setActionCommand("entrar");
		
		btCancelar = new JButton("Cancelar");
		btCancelar.addActionListener(controller);
		btCancelar.setActionCommand("cancelar");

		painelEsquerdo = new JPanel();
		painelCentro = new JPanel();
		painelSul = new JPanel();
		
	}

	@Override
	protected void setupLayout() {
		super.setupLayout();
		this.getPainelForm().setLayout(new BorderLayout());
		this.getPainelBotoes().setVisible(false);
		painelEsquerdo.setLayout(new GridLayout(2, 1, 1, 1));
		painelCentro.setLayout(new GridLayout(2, 1, 1, 1));
		painelSul.setLayout(new FlowLayout());
	}

	@Override
	protected void setupComponentes() {
		super.setupComponentes();

		JPanel aux1 = new JPanel();
		JPanel aux2 = new JPanel();
		JPanel aux3 = new JPanel();
		JPanel aux4 = new JPanel();

		aux1.setLayout(new FlowLayout());
		aux2.setLayout(new FlowLayout());
		aux3.setLayout(new FlowLayout());
		aux4.setLayout(new FlowLayout());

		aux1.add(lbLogin);
		aux2.add(lbSenha);
		aux3.add(txLogin);
		aux4.add(password);

		painelEsquerdo.add(aux1);
		painelEsquerdo.add(aux2);

		painelCentro.add(aux3);
		painelCentro.add(aux4);

		painelSul.add(btEntrar);
		painelSul.add(btCancelar);

		getPainelForm().add(painelEsquerdo, BorderLayout.WEST);
		getPainelForm().add(painelCentro, BorderLayout.CENTER);
		getPainelForm().add(painelSul, BorderLayout.SOUTH);
	}

	public WindowBehavior getWindowBehavior() {
		return windowBehavior;
	}

	public void setWindowBehavior(WindowBehavior windowBehavior) {
		this.windowBehavior = windowBehavior;
	}


}
